//
//  TStarsView.m
//  HighLieChe
//
//  Created by timmy on 16/4/19.
//  Copyright © 2016年 timmy. All rights reserved.
//

#import "TStarsView.h"

#define kCommonStartTag   4444

@interface TStarsView ()

@property(nonatomic,strong)UIButton *button1;
@property(nonatomic,strong)UIButton *button2;
@property(nonatomic,strong)UIButton *button3;
@property(nonatomic,strong)UIButton *button4;
@property(nonatomic,strong)UIButton *button5;

@property(nonatomic,assign)NSInteger currentIndex;

@end

@implementation TStarsView

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        NSInteger mainWidth = frame.size.width;
        for (int i = 0; i < 5; i ++) {
            UIImageView *littleView = [UIImageView new];
            littleView.frame = CGRectMake(i * mainWidth / 5 , 0, mainWidth / 5, mainWidth / 5);
            [littleView setImage:[UIImage imageNamed:@"evaluate_1.png"]];
            [littleView setHighlightedImage:[UIImage imageNamed:@"pinglun.png"]];
            littleView.tag = kCommonStartTag + i;
            littleView.userInteractionEnabled = YES;
            UITapGestureRecognizer *startTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(startTapAction:)];
            [littleView addGestureRecognizer:startTap];
            self.currentIndex = - 1;
            [self addSubview:littleView];
        }
    }

    return self;
}

- (void)startTapAction:(UITapGestureRecognizer *)sender {

    self.currentIndex = sender.view.tag - kCommonStartTag;
    for (NSInteger i = 0; i < self.currentIndex + 1; i ++) {
        UIImageView *hightLight = [self.subviews objectAtIndex:i];
        hightLight.highlighted = YES;
    }
    for (NSInteger i = self.currentIndex + 1 ; i < 5; i ++) {
        UIImageView *hightLight = [self.subviews objectAtIndex:i ];
        hightLight.highlighted = NO;
    }

}

- (NSInteger)getCommentValue {

    return (self.currentIndex + 1) * 20;

}

@end
